app.service('agentIntegralService',['$http','$q','utilService',function($http,$q,utilService){

    /**
     * 增/减积分
     * @param $scope
     * @returns {*}
     */
    this.changeIntegral = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domainAgent + 'manage/integral/changeIntegral',
            method:"PUT",
            data: {
                agentId: $scope.agent.integralRecord.id,
                changeValue: $scope.agent.changeValue,
                description: $scope.agent.description
            }
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    /**
     * 获取所有代理商的总积分余额
     * @param $scope
     * @returns {*}
     */
    this.getTotalIntegral = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domainAgent + 'manage/integral/getTotalIntegral'
        }).then(function(result){
            deferred.resolve(result.data);
        });
        return deferred.promise;
    }
}]);